package org.ade.monak.anak.service;

import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;

import org.ade.monak.anak.service.storage.LogMonakFileManager;

public class DatabaseThreadService implements Runnable{

	public DatabaseThreadService(){
		antrians 			= new ConcurrentLinkedQueue<Runnable>();
	}
	
	public void addDatabaseThread(Runnable runnable){
		synchronized (this) {
			antrians.add(runnable);
			if(!start){
				start = true;
				new Thread(this).start();
			}
		}
	}
	
	public void run() {
		
		while(start){
			Runnable runnable = antrians.poll();
			if(runnable!=null){
				runnable.run();
			}
			synchronized (this) {
				if(antrians.isEmpty()){
					start = false;			
				}
			}
		}
		
	}

	private Queue<Runnable> antrians;
	private boolean start;



}
